package com.web.service.impl;

import com.dto.BaseDto;
import com.dto.MessageEnum;
import com.entity.Activitytype;
import com.entity.Activitytype;
import com.entity.Festival;
import com.page.PageInfo;
import com.web.dao.ActivitytypeDao;
import com.web.dao.ActivitytypeDao;
import com.web.service.ActivitytypeService;
import com.web.service.ActivitytypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
public class ActivitytypeServiceImpl implements ActivitytypeService {
    @Resource
    ActivitytypeDao activitytypeDao;

    public BaseDto<Activitytype> getAll() throws Exception {
        List<Activitytype> activitytypes = activitytypeDao.getAll();
        MessageEnum messageEnum = activitytypes.size() > 0? MessageEnum.GETALLSTUDENTSUCCESS: MessageEnum.GETALLSTUDENTNODATA;
        BaseDto<Activitytype> dto = new BaseDto(messageEnum,activitytypes);

        return dto;
    }

    public BaseDto<Activitytype> selectByPrimaryKey(int atid) throws Exception {
        Activitytype activitytype = activitytypeDao.selectByPrimaryKey(atid);
        MessageEnum messageEnum = Optional.ofNullable(activitytype).isPresent()? MessageEnum.GETALLSTUDENTSUCCESS:MessageEnum.GETALLSTUDENTNODATA;
        BaseDto<Activitytype> dto = new BaseDto(messageEnum,activitytype);

        return dto;
    }

    public BaseDto<Activitytype> getActivitytypesByPage(PageInfo pageInfo) throws Exception {
        List<Activitytype> activitytypes = activitytypeDao.getActivitytypesByPage(pageInfo);
        MessageEnum messageEnum = activitytypes.size() > 0? MessageEnum.GETBYPAGESUCCESS: MessageEnum.GETBYPAGEFAIL;
        BaseDto<Activitytype> dto = new BaseDto(messageEnum,activitytypes);

        return dto;
    }

    public BaseDto<Activitytype> add(Activitytype activitytype) throws Exception {
        int result = activitytypeDao.add(activitytype);
        MessageEnum messageEnum = result > 0? MessageEnum.ADDFESTIVALSUCCESS: MessageEnum.ADDFESTIVALFAIL;
        BaseDto<Activitytype> dto = new BaseDto(messageEnum,result);

        return dto;
    }

    public BaseDto<Activitytype> update(int atid) throws Exception {
        Activitytype activitytype = activitytypeDao.selectByPrimaryKey(atid);
        int result = activitytypeDao.update(activitytype);
        MessageEnum messageEnum = result > 0? MessageEnum.UPDATESUCCESS: MessageEnum.UPDATEFAIL;
        BaseDto<Activitytype> dto = new BaseDto(messageEnum,result);

        return dto;
    }
}
